import http from "@/api";
import { labListType } from "@/views/laboratoryList/type";
import { joinQueryParams } from "@/utils/qs";

// 查询响应类型
interface selectResType {
  list: labListType;
  total: number;
}

// 添加/编辑/删除响应类型
// interface addEditDeleteResType {
//   data: null | Object;
//   msg: string;
//   result: string;
// }

// 使用枚举
enum Api {
  // 分页查询实验室
  selectLaboratoryByPage = "/Laboratory/selectByPage",
  // 添加实验室
  addLaboratory = "/Laboratory/add",
  // 修改实验室
  editLaboratory = "/Laboratory/edit",
  // 删除实验室
  deleteLaboratory = "/Laboratory/delete",
  // 查询所有实验室
  selectAllLab = "/Laboratory/select",
  // 根据名称查询实验室
  selectLabByName = "/Laboratory/selectByName"
}

// 分页查询实验室的Api
export const selectLaboratoryByPageApi = (data: { laboratoryHome: string; page: number; size: number }) => {
  return http.post<selectResType>(Api.selectLaboratoryByPage + joinQueryParams(data), {}, { loading: false });
};

// 添加实验室的Api
export const addLaboratoryApi = (data: { laboratoryHome: string }) => {
  return http.post(Api.addLaboratory + joinQueryParams(data), {}, { loading: false });
};

// 修改实验室的Api
export const editLaboratoryApi = (data: { laboratoryId: number | string | null; laboratoryHome: string }) => {
  return http.post(Api.editLaboratory + joinQueryParams(data), {}, { loading: false });
};

// 删除实验室的Api
export const deleteLaboratoryApi = (data: { laboratoryId: number | string | null }) => {
  return http.post(Api.deleteLaboratory + joinQueryParams(data), {}, { loading: false });
};

// 查询所有实验室的Api
export const selectAllLabApi = () => {
  return http.post<labListType>(Api.selectAllLab, {}, { loading: false });
};

// 根据名称查询实验室的Api
export const selectLabByNameApi = (data: { laboratoryHome: string }) => {
  return http.post(Api.selectLabByName + joinQueryParams(data), {}, { loading: false });
};
